﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using ZXing.Common;

namespace wms.Common
{
    class CodeBarHelper
    {
        //生成条形码
        public static byte[] Generate(String msg, int width, int height)
        {
            // 1.设置条形码规格
            EncodingOptions encodeOption = new EncodingOptions();
            encodeOption.Height = height; // 必须制定高度、宽度
            encodeOption.Width = width;


            // 2.生成条形码图片并保存
            BarcodeWriter wr = new BarcodeWriter();
            wr.Options = encodeOption;

            wr.Format = BarcodeFormat.CODE_128;
            Bitmap img = wr.Write(msg); // 生成图片
            MemoryStream stream = new MemoryStream();
            img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            return stream.ToArray();
        }
    }
}
